package com.myapp.actions.client;

import com.myapp.MyApp;
import com.mydatastore.ClientDataStore;
import com.mydatastore.mysql.client.ClientDataStoreMySQL;
import com.mydatastore.DataStoreException;
import com.myweb.WebAction;
import com.myweb.WebException;
import com.myweb.WebRequest;
import com.myweb.WebResponse;
import com.myweb.annotation.Action;

@Action(url = "clients")
public class ListClients implements WebAction {
  
  @Override
  public void validate(WebRequest req) throws WebException {
  }

  @Override
  public void process(WebRequest req, WebResponse res) throws WebException {
    try {
      ClientDataStore ds = new ClientDataStoreMySQL(MyApp.getConnection());
      res.setResult(ds.list());
      
    } catch (DataStoreException e) {
      throw new WebException(e.getMessage());
    }
  }

  @Override
  public String getRenderer() {
    return "/WEB-INF/client/list.jsp";
  }
}
